package com.example.paper.testSetList;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 获取随机字符串工具类
 */
public class RandomStringGenerator {

    private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
    private static final String NUMBERS = "0123456789";
    private static final String CHAR_ALL = CHAR_LOWER  + NUMBERS;

    public static String generateRandomString(int length) {
        if (length < 1) throw new IllegalArgumentException("Length must be at least 1");
        StringBuilder sb = new StringBuilder(length);
        Random random = new SecureRandom();

        for (int i = 0; i < length; i++) {
            sb.append(CHAR_ALL.charAt(random.nextInt(CHAR_ALL.length())));
        }
        return sb.toString();
    }

    public static List<String> generateRandomStringList(int length, int size) {
        if (length < 1 || size < 1) throw new IllegalArgumentException("Length must be at least 1");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(generateRandomString(length));
        }
        return list;
    }
}
